package java7;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);

	public Integer pop();

	public Integer peek(); 

	public boolean empty(); 

	public int size(); 

}

public class Q5_1 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		IntegerStack liststack = new ArrayListIntegerStack();
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			int k = in.nextInt();
			System.out.println(liststack.push(k));
		}
		System.out.printf(liststack.peek() + ",");
		System.out.printf(liststack.empty() + ",");
		System.out.println(liststack.size());
		System.out.println(liststack);
		int x = in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(liststack.pop());
		}
		System.out.printf(liststack.peek() + ",");
		System.out.printf(liststack.empty() + ",");
		System.out.println(liststack.size());
		System.out.println(liststack);
		in.close();
	}
}

class ArrayListIntegerStack implements IntegerStack {
	private List<Integer> list;

	public ArrayListIntegerStack() {
		list = new ArrayList<Integer>();
	}

	@Override
	public Integer push(Integer item) {
		if (item == null)
			return null;
		list.add(item);
		return item;
	}

	@Override
	public Integer pop() {
		if (list.size() == 0)
			return null;
		return list.remove(list.size()-1);
	}
	
	@Override
	public String toString() {
		return list.toString();
	}
	@Override
	public Integer peek() {
		if (list.size() == 0)
			return null;
		return list.get(list.size()-1);
	}

	@Override
	public boolean empty() {
		if (list.size() == 0)
			return true;
		return false;
	}

	@Override
	public int size() {
		return list.size();
	}
}
